﻿using HartConfigTool.HARTCommands;
using HartConfigTool.SerialPortUtil;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HartConfigTool.Commands.SystemCMDs
{
    internal class SystemCMDSetup : CMDsBase
    {
        protected readonly byte[] cmdCode = { 0xFF, 0xFF, 0xFF, 0xAA, 0x55, 0x01, 0x0D, 0x0A, 0xff};

        public SystemCMDSetup(SerialPortsManager serialPortManager) 
        {
            ConfigurationParameters(serialPortManager);
        }
        protected override async Task SendCMDAsync()
        {
            serialPortManager.DebugMessage("[" + DateTime.Now + "]:-->" + HARTProtocolV7.HexToString(cmdCode) + "\r\n");
            await serialPortManager.SendCMD(cmdCode);
        }

        public override async Task ParseResponse(byte[] responseData)
        {
            await Task.Run(() => {
                byte[] data = null;

                data = serialPortManager.GetRxBufferData();

                // Debug Message
                serialPortManager.DebugMessage("[" + DateTime.Now + "]:<--" + HARTProtocolV7.HexToString(data) + "\r\n");

                this.serialPortManager.RxDataClear();
            });
        }
    }
}
